package ngat.oss.simulation.metrics;

import ngat.oss.simulation.*;
import ngat.phase2.*;

/** Calculates the integrated priority SQM.*/
public class PriorityUtilityCalculator implements UtilityCalculator {

    /** Exec timing and feasibility model.*/
    private ExecutionTimingModel execModel;

    /** Create a PriorityUtilityCalculator using the supplied ExecutionTimingModel.*/ 
    public PriorityUtilityCalculator(ExecutionTimingModel execModel) {
	this.execModel = execModel;
    }
    
    /** Return the utility for the specified group at time under env and hist (not used).
     * Background are treated as zero as they are NOT required to execute. 
     * Standards are treated as 3 which is how they are currently selected, this may be changed
     * in the future. They are still part of the overall science program.
     */
    public double getUtility(Group group, long time, EnvironmentSnapshot env, ExecutionStatistics hist) {

	double exec = (double)execModel.getExecTime(group);
	double pp   = 0.0;

	switch (group.getPriority()) {
	case -2:
	    pp = 0.0;
	    break;
	case -1:
	    pp = 3.0;
	    break;
	case 0:
	    pp = 1.0;
	    break;
	default:
	    pp = (double)group.getPriority();
	}

	return pp*exec;
    }
    
}
